class TreeNode {
    val: number
    left: TreeNode | null
    right: TreeNode | null
    constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
        this.val = (val === undefined ? 0 : val)
        this.left = (left === undefined ? null : left)
        this.right = (right === undefined ? null : right)
    }
}
function isSymmetric(root: TreeNode | null): boolean {
    if (root == null) {
        return true;
    }
    let lnode = root.left;
    let rnode = root.right;
    // if (lnode == null && rnode == null) {
    //     return true;
    // }
    if (lnode == null || rnode == null || lnode?.val != rnode?.val) {
        return false;
    }

    let llist = new Array<TreeNode | null>();
    let rlist = new Array<TreeNode | null>();
    llist.push(lnode);
    rlist.push(rnode);
    while (llist.length > 0 || rlist.length > 0) {
        console.log(llist,rlist);
        
        if (llist.length != rlist.length) {
            return false;
        }
        let l = llist.shift();
        let r = rlist.shift();
        if (l == null && r == null) {
            continue;
        }
        if ((l == null || r == null) || l.left?.val != r.right?.val || l.right?.val != r.left?.val) {
            return false;
        }
        if(l.left != null && r.right !=null){
            llist.push(l.left);
            rlist.push(r.right);
        }
        if(l.right!=null && r.left!=null){
            llist.push(l.right);
            rlist.push(r.left);
        }
    }

    return true;
};


// function tes(root: TreeNode | null){
//     console.log(root?.val);
// }

// tes(null);

console.log(undefined != undefined);

